package com.atguigu.mq.listener;

import com.rabbitmq.client.Channel;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class MyMessageListener1111 {

    public static final String EXCHANGE_NORMAL = "exchange.normal.video";
    public static final String EXCHANGE_DEAD_LETTER = "exchange.dead.letter.video";

    public static final String ROUTING_KEY_NORMAL = "routing.key.normal.video";
    public static final String ROUTING_KEY_DEAD_LETTER = "routing.key.dead.letter.video";

    public static final String QUEUE_NORMAL = "queue.normal.video";
    public static final String QUEUE_DEAD_LETTER = "queue.dead.letter.video";
    @RabbitListener(queues = {QUEUE_NORMAL})
    public void queue(String messageContent, Message message, Channel channel) throws IOException, InterruptedException {
        log.info("我是正常消费队列 messageContent = " + messageContent);
        //Thread.sleep(1000);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
    @RabbitListener(queues = {QUEUE_DEAD_LETTER})
    public void queue2(String messageContent, Message message, Channel channel) throws IOException {
        log.info("我是死信消费队列 messageContent = " + messageContent);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
